<?php
require ('../include/init.inc.php');
$method = $machine_id = $page_no='';
extract ( $_GET, EXTR_IF_EXISTS );

$start_date = trim($_GET['start_date']);
$end_date = trim($_GET['end_date']);
$search_val = trim($_GET['search_val']);
$orderByFiled = trim($_GET["orderByFiled"]);
$descOrAsc = trim($_GET["descOrAsc"]);

//START 数据库查询及分页数据
if($start_date != '' && $end_date !=''){
	$row_count =Machine::getCountByDate($start_date,$end_date,$search_val);
}else{
	$row_count = Machine::count ($search_val);
}
// echo $row_count;
$page_size = PAGE_SIZE;
$page_no=$page_no<1?1:$page_no;

$total_page=$row_count%$page_size==0?$row_count/$page_size:ceil($row_count/$page_size);
$total_page=$total_page<1?1:$total_page;
$page_no=$page_no>($total_page)?($total_page):$page_no;

$start = ($page_no - 1) * $page_size;

if ($method == 'del' && ! empty ( $machine_id )) {
	$machine = Machine::getMachineById($machine_id);
	$result = Machine::delMachine ( $machine_id );
	if ($result>0) {
		SysLog::addLog ( UserSession::getUserName(), 'DELETE', 'Machine',$machine_id, json_encode($machine) );
		Common::exitWithSuccess ('已将主机删除','panel/machine.php');
	}else{
		OSAdmin::alert("error");
	}
	
}


$machines = Machine::getMachines($class_name,$start ,$page_size,$start_date,$end_date,$search_val,$orderByFiled ,$descOrAsc);

$page_html=Pagination::showPager("machine.php?start_date=$start_date&end_date=$end_date&search_val=$search_val",$page_no,PAGE_SIZE,$row_count);

$responst_user = $_SESSION["osa_user_info"]["real_name"];

Template::assign ( 'page_no', $page_no );
Template::assign ( 'page_size', PAGE_SIZE );
Template::assign ( 'row_count', $row_count );
Template::assign ( 'page_html', $page_html );
Template::assign ( '_GET', $_GET );
Template::assign ( 'responst_user', $responst_user );


$confirm_html = OSAdmin::renderJsConfirm("icon-remove");
Template::assign ( 'osadmin_action_confirm' , $confirm_html);
Template::assign ( 'machines', $machines );
Template::display ( 'panel/machine.tpl' );


